﻿using Czar.HtmlToPdfImage;

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Edu.ZJ
{
    public class HtmlToPdf : ToPdfResultBase
    {
        public HtmlToPdf()
        {

        }

        public HtmlToPdf(string html)
        {
            Html = html;
        }

        public string Html { get; set; }

        public void SaveFile(string SaveOnServerPath)
        {
            if (string.IsNullOrEmpty(Html))
            {
                return;
            }
            if (string.IsNullOrEmpty(SaveOnServerPath))
            {
                return;
            }

            this.WkhtmlPath = WkhtmltoxConfig.WkhtmltoxPath;
            var fileContent = WkhtmltopdfDriver.ConvertHtml(this.WkhtmlPath, GetConvertOptions(), Html);
            var directoryName = Path.GetDirectoryName(SaveOnServerPath);
            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }
            File.WriteAllBytes(SaveOnServerPath, fileContent);
        }
    }
}
